package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.bean.Student;
import com.itheima.mapper.StudentMapper;
import com.itheima.service.StudentService;
import com.itheima.utils.DaoInstanceFactory;

import java.util.List;

public class StudentServiceImpl implements StudentService {

    public PageInfo findByPage(String currentPage, String pageSize) {
        // 调用dao分页查询
        PageHelper.startPage(Integer.parseInt(currentPage),Integer.parseInt(pageSize));

        // 查询
        StudentMapper mapper = DaoInstanceFactory.getMapper(StudentMapper.class);
        List<Student> studentList = mapper.findAll();

        // 创建PageInfo
        PageInfo info = new PageInfo(studentList);
        return info;
    }

    @Override
    public void addStu(Student student) {
        StudentMapper mapper = DaoInstanceFactory.getMapper(StudentMapper.class);
        mapper.addStu(student);
    }

    @Override
    public void updateStu(Student student) {
        StudentMapper mapper = DaoInstanceFactory.getMapper(StudentMapper.class);
        mapper.updateStu(student);
    }

    @Override
    public void deleteStu(String number) {
        StudentMapper mapper = DaoInstanceFactory.getMapper(StudentMapper.class);
        mapper.deleteStu(number);
    }
}
